<?php
/**
 * 
 * @author DUCHIEU
 *
 */
class Service_Manager{
    /**
     * Returns download by date in database
     *
     * @param string $user
     * @param string $pass
     * @param string $date
     * @return array|Exception
     */
    public function getDownloadByDate($user,$pass,$date) 
    {
    	if(strcmp($user, 'hieubd@sunnet.vn')==0 && strcmp($pass, 'hieubd@sunnet.vn')==0){
	    	$validator = new Zend_Validate_Date();
	      	if (!$validator->isValid($date)){
	        	throw new Service_Exception('Invalid input');          
	      	}
	      	
	      	$db = Zend_Registry::get('connectDB');
			$mySql = $db->select()
						->from('download');
			if($date) $mySql->where('time=?',$date);
			$result = $db->fetchAll($mySql);   
	      	if (!count($result)) {        
	        	throw new Exception('Invalid download by date: ' . $date);  
	      	} 
    	}else{
    		throw new Service_Exception('Username and password is incorrect');
    	}
     	return $result;
    }
}
